package edu.vt.ece4564.bluetendance.login;

import java.sql.ResultSet;

import javax.servlet.http.HttpServletResponse;

import edu.vt.ece4564.bluetendance.database.DatabaseConnector;
import edu.vt.ece4564.bluetendance.database.DatabaseStrings;

public class ServerLoginHandler implements Runnable{
	private HttpServletResponse response;
	private String username;
	private String password;
	
	public ServerLoginHandler(String username, String password, HttpServletResponse response) {
		this.username = username;
		this.password = password;
		this.response = response;
	}

	@Override
	public void run() {
		String query = "SELECT * FROM " + DatabaseStrings.databaseName + "." + DatabaseStrings.usersTableName + " WHERE Username='" + this.username + "' AND Password='" + this.password + "';";
		
		DatabaseConnector dc = DatabaseConnector.get();
		dc.commandText = query;
		ResultSet results = dc.executeQuery();
		
		if (dc.getQueryResultsList(results).size() != 0) {
			response.addHeader("success", "true");
		}
		else {
			response.addHeader("success", "false");
		}
	}
}
